﻿#include "../../inc/helper.hpp"

int main()
{
	zmq::context_t ctx;
	zmq::socket_t server(ctx, zmq::socket_type::rep);
	server.bind("tcp://*:5555");

	int cycles = 0;
	while (1)
	{
		std::string request = receive_string(server);
		++cycles;

		if (cycles > 3 && rand() % 100 == 0)
		{
			info("simulating a crash");
			break;
		}
		else if (cycles > 3 && rand() % 3 == 0)
		{
			info("simulating CPU overload");
			std::this_thread::sleep_for(std::chrono::seconds(2));
		}

		info("normal request ({})", request);
		std::this_thread::sleep_for(std::chrono::seconds(1));
		send_string(server, request);
	}
}